package com.woniuxy.ticketuser.rabbitMQ;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

/**
 * @ClassName Demo
 * @Description
 * @Author zx
 * @Date 2021-03-10 11:18:12
 * @Version 1.0
 */
public class RabbitMQSend {
    private final static String QUEUE_NAME = "hello_publish";
    private static final String EXCHANGE_NAME = "ex1";
    public static void main(String[] args) {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        try (Connection connection = factory.newConnection();
             Channel channel = connection.createChannel()) {
            //交换机的类型
            channel.queueDeclare(QUEUE_NAME, false, false, false, null);
            String message = "Hello 你好!";
            channel.basicPublish(EXCHANGE_NAME,"", null, message.getBytes());
            System.out.println(" [x] Sent '" + message + "'");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
